﻿using System;

namespace DDDSample.Domain.Cargo
{
    public class RouteSpecification
    {
        private readonly DateTime _arrivalDeadline;
        private readonly Location.Location _origin;
        private readonly Location.Location _destination;

        protected RouteSpecification()
        {
        }     

        public RouteSpecification(Location.Location origin, Location.Location destination, DateTime arrivalDeadline)
        {
            if (origin == null)
            {
                throw new ArgumentNullException("origin");
            }
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            if (origin == destination)
            {
                throw new ArgumentException("Origin and destination can't be the same.");
            }

            _origin = origin;
            _arrivalDeadline = arrivalDeadline;
            _destination = destination;
        }

        public virtual bool IsSatisfiedBy(Itinerary itinerary)
        {
            return Origin == itinerary.InitialDepartureLocation &&
                   Destination == itinerary.FinalArrivalLocation &&
                   ArrivalDeadline > itinerary.FinalArrivalDate;
        }

        public DateTime ArrivalDeadline
        {
            get { return _arrivalDeadline; }
        }

        public Location.Location Origin
        {
            get { return _origin; }
        }

        public Location.Location Destination
        {
            get { return _destination; }
        }
    }
}